
#############################################################################
#							SORT General CMAKE								#
#    				Copyright (C) 2012  J.R. Ruiz-Sarmiento					#
#																			#
#    This program is free software: you can redistribute it and/or modify	#
#    it under the terms of the GNU General Public License as published by	#
#    the Free Software Foundation, either version 3 of the License, or		#
#    (at your option) any later version.									#
#																			#
#    This program is distributed in the hope that it will be useful,		#
#    but WITHOUT ANY WARRANTY; without even the implied warranty of			#
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the			#
#    GNU General Public License for more details.							#
#																			#
#    You should have received a copy of the GNU General Public License		#
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.	#
#																			#
#############################################################################

# Project name	
PROJECT(SORT)

# Required commands in newer CMake versions:
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

# Loads the current version number (e.g "0.5.1")
FILE(READ "${CMAKE_SOURCE_DIR}/version_prefix.txt" PROTOCOL_VERSION_NUMBER)

STRING(SUBSTRING "${PROTOCOL_VERSION_NUMBER}" 0 1 PROTOCOL_VERSION_NUMBER_MAJOR)
STRING(SUBSTRING "${PROTOCOL_VERSION_NUMBER}" 2 1 PROTOCOL_VERSION_NUMBER_MINOR)
STRING(SUBSTRING "${PROTOCOL_VERSION_NUMBER}" 4 1 PROTOCOL_VERSION_NUMBER_PATCH)

# Use MRPT:
FIND_PACKAGE( MRPT REQUIRED slam gui  hwdrivers)

# PCL library:
# --------------------------------------------
SET(CMAKE_OPENMORA_HAS_PCL 0)
find_package(PCL 1.5 REQUIRED)
if (PCL_FOUND)
	SET(CMAKE_OPENMORA_HAS_PCL 1)

	INCLUDE_DIRECTORIES(${PCL_INCLUDE_DIRS})
	link_directories(${PCL_LIBRARY_DIRS})
	add_definitions(${PCL_DEFINITIONS})

endif(PCL_FOUND)

# OpenCV
# Try to find OpenCV config file (NO_MODULE: Don't find a module, but OpenCVConfig.cmake):
# --------------------------------------------
FIND_PACKAGE(OpenCV NO_MODULE)
ADD_DEFINITIONS(/DOPENCV_VERSION=${OpenCV_VERSION})

# The debug post-fix of .dll /.so libs
# ------------------------------------------
set(CMAKE_DEBUG_POSTFIX  "-dbg")

#
# Add 3rdParties libraries
#
set(TINY_XML_LIBS "${CMAKE_SOURCE_DIR}/3rdParties/tinyXML/lib/tinyxml.lib") #;${CMAKE_SOURCE_DIR}/3rdParties/tinyXML/lib/tinyxmlSTL.lib")
set(TINY_XML_INCLUDE "${CMAKE_SOURCE_DIR}/3rdParties/tinyXML/include")

INCLUDE_DIRECTORIES( ${TINY_XML_INCLUDE} )

#message(TINY_XML_LIBS: ${TINY_XML_LIBS})

#  Copy the configuration file:
CONFIGURE_FILE(
	"${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.ini"
	"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.ini"
	@ONLY)

# Create SORT libraries and add include directories to the Test area
SET( SORT_LIBRARIES "ObjectRecognition;DataIO;Adapters" )

FOREACH( LIBRARY ${SORT_LIBRARIES} )
	ADD_SUBDIRECTORY(libs/${LIBRARY})
	INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libs/${LIBRARY})
ENDFOREACH( LIBRARY ${SORT_LIBRARIES} )


# Libs are: "libsort-xxx"
#            ---
set(LIB_PREFIX "libsort-")

# ------------------------------------------
# TestPlace
# ------------------------------------------

# Define the executable target:
ADD_EXECUTABLE(TestPlace ${CMAKE_SOURCE_DIR}/libs/Test/main.cpp)

# Link the executable
TARGET_LINK_LIBRARIES(TestPlace ${PCL_LIBRARIES} ${MRPT_LIBS} ${OpenCV_LIBS} ${TINY_XML_LIBS} ObjectRecognition DataIO Adapters )